# -*- coding: utf-8 -*-

__author__ = """WebLion <support@weblion.psu.edu>"""
__docformat__ = 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from Products.ATContentTypes.content.base import ATCTContent
from Products.ATContentTypes.content.schemata import ATContentTypeSchema, finalizeATCTSchema
from Products.ContactsDirectory.config import *
from Products.ContactsDirectory.interfaces.organizationmembership import IOrganizationMembership
from zope.interface import implements

schema = ATContentTypeSchema.copy() + Schema((

    StringField(
        name='position',
        widget=StringWidget(
            label=u'Position',
            label_msgid='ContactsDirectory_label_position',
            i18n_domain='ContactsDirectory',
        )
    ),

    StringField(
        name='title',
        default="Position",
        widget=StringWidget(
            visible={'edit':'invisible', 'view':'visible'},
            label=u'Title',
            label_msgid='ContactsDirectory_label_title',
            i18n_domain='ContactsDirectory',
        ),
        accessor="Title"
    ),

),
)

OrganizationMembership_schema = BaseSchema.copy() + schema.copy()
finalizeATCTSchema(OrganizationMembership_schema)

class OrganizationMembership(BaseContent, ATCTContent):
    """
    """
    security = ClassSecurityInfo()
    __implements__ = (getattr(BaseContent,'__implements__',()),)
    implements(IOrganizationMembership)
    meta_type = portal_type = 'CDOrganizationMembership'

    # moved schema setting after finalizeATCTSchema, so the order of the fieldsets
    # is preserved. Also after updateActions is called since it seems to overwrite the schema changes.
    # Move the description field, but not in Plone 2.5 since it's already in the metadata tab. Although, 
    # decription and relateditems are occasionally showing up in the "default" schemata. Move them
    # to "metadata" just to be safe.
    if 'categorization' in OrganizationMembership_schema.getSchemataNames():
        OrganizationMembership_schema.changeSchemataForField('description', 'categorization')
    else:
        OrganizationMembership_schema.changeSchemataForField('description', 'metadata')
        OrganizationMembership_schema.changeSchemataForField('relatedItems', 'metadata')


    _at_rename_after_creation = True

    schema = OrganizationMembership_schema

    # Methods
registerType(OrganizationMembership, PROJECTNAME)
# end of class OrganizationMembership

